package com.innovation.chengzhangriji.ui.adapter;


import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.support.v7.widget.RecyclerView;
import android.util.StateSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.innovation.chengzhangriji.R;
import com.innovation.chengzhangriji.ui.widget.CuteBabyAvatarView;
import com.innovation.chengzhangriji.ui.widget.CuteImageView;
import com.makeramen.roundedimageview.RoundedImageView;

public class DiaryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    private OnItemClickListener onItemClickListener;

    public TextView txtDiaryName, txtDiaryAge;

    public CuteImageView imageEdit;

//    public ImageView imageSex;
//
//    public RoundedImageView roundedHeadView;

    public CuteBabyAvatarView roundedHeadView;

    public View lineView;

    public DiaryViewHolder(View itemView, OnItemClickListener onItemClickListener) {
        super(itemView);
        txtDiaryName = (TextView) itemView.findViewById(R.id.text_diary_name);
        txtDiaryAge = (TextView) itemView.findViewById(R.id.text_diary_age);
        imageEdit = (CuteImageView) itemView.findViewById(R.id.image_edit);
        imageEdit.setClickable(true);
        // imageSex = (ImageView) itemView.findViewById(R.id.image_head_sex);
        // roundedHeadView = (RoundedImageView) itemView.findViewById(R.id.avatar_view);
        roundedHeadView = (CuteBabyAvatarView) itemView.findViewById(R.id.avatar_layout);
        lineView = itemView.findViewById(R.id.line);

        // 设置按下的颜色反馈
        StateListDrawable drawable = new StateListDrawable();
        drawable.addState(new int[] {android.R.attr.state_pressed}, new ColorDrawable(itemView.getResources().getColor(R.color.theme_bg)));
        drawable.addState(StateSet.NOTHING, new ColorDrawable(itemView.getResources().getColor(android.R.color.white)));
        itemView.setBackgroundDrawable(drawable);

        // 点击事件
        this.onItemClickListener = onItemClickListener;
        itemView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        onItemClickListener.OnItemClick(getLayoutPosition());
    }
}